//
//  HomeRecommendTableViewCell.swift
//  XMYouPin
//
//  Created by 王宗成 on 2019/7/6.
//  Copyright © 2019 王宗成. All rights reserved.
//

import UIKit

class HomeRecommendTableViewCell: WZC_TableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    var model:HomeFloorModel?
    {
        didSet
        {
            self.gridView.reloadData()
        }
    }
    
    

    lazy var gridView : UICollectionView = {
        let layout = UICollectionViewFlowLayout.init()
        layout.sectionInset = UIEdgeInsets(top: 3, left: 10, bottom: 3, right: 10)
        layout.scrollDirection = UICollectionView.ScrollDirection.vertical
        layout.minimumInteritemSpacing = 3
        layout.minimumLineSpacing = 3
        layout.itemSize = CGSize.init(width: (kScreenW-23)/2, height:130*kHeightRatio)
        
        let collectionView = UICollectionView.init(frame:CGRect(x: 0, y: 0, width: kScreenW, height: 265*kHeightRatio+3*3), collectionViewLayout: layout)
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.backgroundColor = UIColor.white

        collectionView.register(RecommendCollectionViewCell.self, forCellWithReuseIdentifier: "RecommendCollectionViewCell")
        self.addSubview(collectionView)
        return collectionView
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
//        gridView.snp.makeConstraints { (make) in
//
//            make.top.left.bottom.right.equalToSuperview()
//        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}

extension HomeRecommendTableViewCell:UICollectionViewDelegate,UICollectionViewDataSource
{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        

        return model?.data?.items.count ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell:RecommendCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "RecommendCollectionViewCell", for: indexPath) as! RecommendCollectionViewCell
        cell.model = model?.data?.items[indexPath.row].item

        return cell
    }
    
}
